"use strict";
const BaseImpl = require("../basics/clz/baseimpl");
const MasterModel = require("../model/master");
const TempApi = require("../taobao/temp");

/**
 * 通用服务
 */
class HomeImpl extends BaseImpl {


  async onlineTemp(params) {
    let { openId,app_id, shopseesion, accessToken } = this.params;
    if (!shopseesion || shopseesion == "0") {
      shopseesion = accessToken;
    }
    return await TempApi.onlineapp(this.cloud, shopseesion, this.params);;
  }

  /**
   * 查询实例列表
   * @param {String} templateId 
   */
  async queryTempList(templateId, shopseesion) {
    let temps = await TempApi.selectList(this.cloud, shopseesion, { template_id: templateId });
    if (!temps) {
      return [];
    }
    let tempList = [];
    for (let i = 0; i < temps.length; i++) {
      const el = temps[i];
      let appInfo = el.app_info;
      appInfo.app_list = el.app_version_list.mini_app_instance_version_dto;
      appInfo.app_list.sort(function (a, b) {
        return a.app_version < b.app_version;
      });
      tempList.push(appInfo);
    }
    return tempList;
  }

}

module.exports = HomeImpl;